/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.common.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.javaeye.common.dto.Role;

public class RoleDAOHibernate extends HibernateDaoSupport implements RoleDAO {
	
	@SuppressWarnings("unchecked")
	public List<Role> getRoles() {
		return getHibernateTemplate().find("from Role");
	}
	
	public Role saveRole(Role role) {
		getHibernateTemplate().saveOrUpdate(role);
		return role;
	}
	
	public void removeRole(int roleId) {
		Object o = getHibernateTemplate().load(Role.class, roleId);
		getHibernateTemplate().delete(o);
	}
	
	public Role getRole(int roleId) {
		return (Role)getHibernateTemplate().get(Role.class, roleId);
	}
}
